
<?php $baseUrl=Zend_Controller_Front::getInstance()->getBaseUrl(); ?>
<link rel="stylesheet" rev="stylesheet" href="<?php  echo $baseUrl; ?>/css/home.css" type="text/css" media="all" />
<input type="hidden" id="baseUrl" value="<?php echo $baseUrl; ?>"/>
<script type="text/javascript" language="javascript">
    var baseUrl=$('#baseUrl').val();
    var currentPageBestSeller=1;
    var currentPageMostBought=1;
    var currentRecommendBook=1;
    
    $(document).ready(function()
    {
       setCurrentPageNew(1);
       setCurrentPageInterest(1);
       setCurrentPageBestSeller(0);
       setCurrentPageMostBought(0);
       setCurrentPageRecommendBook(0);
    }
    );

    function loadNewBook(pagesize,currentpage)
    {
        var content="<table width='100%'><tr>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td></tr><tr>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td></tr><tr>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td></tr><table>";
        $('#newbook').html(content);

         $.ajax({
              type:'GET',
              async: true,
              cache: false,
              timeout: 30000,
              url: baseUrl + '/default/ajax/new?current='+currentpage+'&pagesize='+pagesize,
              success:function(data)
              {
                if(data!="")
                {
                    $('#newbook').html(data);
                }
                else
                {

                }
              }
        });
    }

    function loadBookInterest(pagesize,currentpage)
    {
        var content="<table width='100%'><tr>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td></tr><tr>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td></tr><table>";
        $('#popularbook').html(content);

         $.ajax({
              type:'GET',
              async: true,
              cache: false,
              timeout: 30000,
              url: baseUrl + '/default/ajax/interest?current='+currentpage+'&pagesize='+pagesize,
              success:function(data)
              {
                if(data!="")
                {
                    $('#popularbook').html(data);
                }
                else
                {

                }
              }
        });
    }

    function loadBestSeller(pagesize,currentpage)
    {
         var content="<table width='100%'><tr>\n\
            <td><a><img src='"+baseUrl+"/images/arrow1.png' alt='' id='Img5' /></a></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><a><img src='"+baseUrl+"/images/arrow2.png' alt='' id='Img6' /></a></td></tr><table>";
        $('#famousbook').html(content);

         $.ajax({
              type:'GET',
              async: true,
              cache: false,
              timeout: 30000,
              url: baseUrl + '/default/ajax/bestseller?current='+currentpage+'&pagesize='+pagesize,
              success:function(data)
              {
                if(data!="")
                {
                    $('#famousbook').html(data);
                }
                else
                {

                }
              }
        });
    }

    function loadMostBought(pagesize,currentpage)
    {
        var content="<table width='100%'><tr>\n\
            <td><a><img src='"+baseUrl+"/images/arrow1.png' alt='' id='Img3' /></a></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><a><img src='"+baseUrl+"/images/arrow2.png' alt='' id='Img4' /></a></td></tr><table>";
        $('#mostboughtbook').html(content);
        
         $.ajax({
              type:'GET',
              async: true,
              cache: false,
              timeout: 30000,
              url: baseUrl + '/default/ajax/mostbought?current='+currentpage+'&pagesize='+pagesize,
              success:function(data)
              {
                if(data!="")
                {
                    $('#mostboughtbook').html(data);
                }
                else
                {

                }
              }
        });
    }

    function loadRecommendBook(pagesize,currentpage)
    {
        var content="<table width='100%'><tr>\n\
            <td><a><img src='"+baseUrl+"/images/arrow1.png' alt='' id='Img1' /></a></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><img src='"+baseUrl+"/images/loading.gif"+"'/></td>\n\
            <td><a><img src='"+baseUrl+"/images/arrow2.png' alt='' id='Img2' /></a></td></tr><table>";
        $('#recommand').html(content);

         $.ajax({
              type:'GET',
              async: true,
              cache: false,
              timeout: 30000,
              url: baseUrl + '/default/ajax/recommend?current='+currentpage+'&pagesize='+pagesize,
              success:function(data)
              {
                if(data!="")
                {
                     $('#recommand').html(data);
                }
                else
                {

                }
              }
        });
    }

    function setCurrentPageNew(value)
    {
        if(value==1)
        {
            $('#pagenew2').removeClass('active');
            $('#pagenew3').removeClass('active');
        }
        if(value==2)
        {
            $('#pagenew1').removeClass('active');
            $('#pagenew3').removeClass('active');
        }
        if(value==3)
        {
            $('#pagenew1').removeClass('active');
            $('#pagenew2').removeClass('active');
        }
        $('#pagenew'+value).addClass('active');
        loadNewBook(9,value);
    }

    function setCurrentPageInterest(value)
    {
        if(value==1)
        {
            $('#pageinterest2').removeClass('active');
            $('#pageinterest3').removeClass('active');
        }
        if(value==2)
        {
            $('#pageinterest1').removeClass('active');
            $('#pageinterest3').removeClass('active');
        }
        if(value==3)
        {
            $('#pageinterest1').removeClass('active');
            $('#pageinterest2').removeClass('active');
        }
        $('#pageinterest'+value).addClass('active');
        loadBookInterest(6,value);
    }

    function setCurrentPageBestSeller(value)
    {
        currentPageBestSeller +=value;
        if(currentPageBestSeller <=0)
            currentPageBestSeller=10;
        if(currentPageBestSeller>10)
            currentPageBestSeller=1;

        $('#pagebestseller').html('trang '+currentPageBestSeller+'/10');
        loadBestSeller(3,currentPageBestSeller);
    }

    function setCurrentPageMostBought(value)
    {
        currentPageMostBought +=value;
        if(currentPageMostBought <=0)
            currentPageMostBought=10;
        if(currentPageMostBought>10)
            currentPageMostBought=1;

        $('#pagemostbought').html('trang '+currentPageMostBought+'/10');
        loadMostBought(3,currentPageMostBought);
    }

    function setCurrentPageRecommendBook(value)
    {
        currentRecommendBook +=value;
        if(currentRecommendBook <=0)
            currentRecommendBook=2;
        if(currentRecommendBook>2)
            currentRecommendBook=1;

        $('#pagerecommend').html('trang '+currentRecommendBook+'/2');
        loadRecommendBook(5,currentRecommendBook);
    }
</script>

<div id="body_middle">
    <div id="newbookHeader" class="header">
        <h4>Sách mới</h4>
    </div>
    <div id="newbook">
        <!-- ajax for loading content-->
    </div>
    <div class="pager">
        <b>Trang</b>
            <a id="pagenew1" href="#newbookHeader" onclick="setCurrentPageNew(1)">1</a>|
            <a id="pagenew2" href="#newbookHeader" onclick="setCurrentPageNew(2)">2</a>|
            <a id="pagenew3" href="#newbookHeader" onclick="setCurrentPageNew(3)">3</a>
    </div>
    <div class="clear"></div>

    <div id="popularbookHeader" class="header">
        <h4>Sách được đón đọc nhiều nhất</h4>
    </div>
    <div id="popularbook">
        <!-- ajax for loading content-->
    </div>
    <div class="pager">
        <b>Trang</b>
            <a id="pageinterest1" href="#popularbookHeader" onclick="setCurrentPageInterest(1)">1</a>|
            <a id="pageinterest2" href="#popularbookHeader" onclick="setCurrentPageInterest(2)">2</a>|
            <a id="pageinterest3" href="#popularbookHeader" onclick="setCurrentPageInterest(3)">3</a>
    </div>
    <div class="clear"></div>
    
    <div id="famousbookHeader"  class="header">
        <h4>Sách nổi tiếng</h4>
    </div>
    <div id="pagebestseller" class="currentpage">trang 1/10</div>
    <div class="clear1"></div>
    <div id="famousbook">
         <!-- ajax for loading content-->
    </div>
    <div class="clear"></div>

    <div  id="mostboughtbookHeader" class="header">
        <h4>Sách được mua nhiều nhất</h4>
    </div>
    <div id="pagemostbought" class="currentpage">trang 1/10</div>
    <div class="clear1"></div>
    <div id="mostboughtbook" >
        <!-- ajax for loading content-->
    </div>
</div>

<div class="clear"></div>
<?php
    if(isset($this->haveRecommend))
    {
?>
<div id="recommandHeader" class="title">
    <h4>Những cuốn sách có thể phù hợp với bạn</h4>
</div>
<div id="pagerecommend" class="currentpage">trang 1/2</div>
<div  id="recommand">
</div>
<?php
    }
    else if(isset($this->login))
    {
        echo '<h4>Hiện chưa có sách gợi ý. Hãy xem thêm sách để nhận được gợi ý phù hợp!</h4>';
    }
?>
